﻿using DX_Recognize.Common;
using DX_Recognize.Entitys;
using DX_Recognize.Utils;
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.Linq;
using System.Security.Cryptography;
using System.Windows.Forms;
using ZwSoft.ZwCAD.Geometry;
using static DX_Recognize.Utils.ConvertUtils;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

//配置
namespace DX_Recognize.Disposition
{
    public class Mould
    {     
        //查询配置
        public void SetDisposition()
        {
            string SQLServerAddr = "139.159.178.26";
            string UID = "CAM";
            string PWD = "CAM";
            string SQLConnectionString = $"Server={SQLServerAddr};Database=DXMG;UID={UID};PWD={PWD}";
            SqlConnection sqlConnection = new SqlConnection(SQLConnectionString);
            var conn = sqlConnection;
            conn.Open();

            string dispositionSQL =
                 "SELECT * FROM [DXMG].[dbo].[V_Steel_List] " +
                 "SELECT * FROM [DXMG].[dbo].[StandardEGP]" +
                 "SELECT * FROM [DXMG].[dbo].[StandardGP]" +
                 "SELECT * FROM [DXMG].[dbo].[StandardRP]" +
                 "SELECT * FROM [DXMG].[dbo].[StandardSP]" +
                 "SELECT * FROM [DXMG].[dbo].[StandardScrew]" +
                 "SELECT * FROM [DXMG].[dbo].[R2D_Category_Board]" +
                 "SELECT DISTINCT short_name,category FROM [DXMG].[dbo].[R2D_Category_Board] " +
                 "SELECT * FROM [DXMG].[dbo].[MC2_3DStandardHoleData]" +
                 "SELECT * FROM [DXMG].[dbo].[V_Customers]" +
                 "SELECT * FROM [DXMG].[dbo].[R2D_Mould_Series_Size_Item]" +
                 "SELECT * FROM [DXMG].[dbo].[R2D_QuoUser]" +
                 "SELECT * FROM [DXMG].[dbo].[StandardThick]" +
                 "SELECT * FROM [DXMG].[dbo].[MC2_3DBoardStandard]" +
                 "SELECT * FROM [DXMG].[dbo].[MC_SPScrewMeson]" +
                 "SELECT * FROM [DXMG].[dbo].[R2D_Norm_Category_Board_Sub]" + 
                 "SELECT * FROM [DXMG].[dbo].[MC2_3DPullingSize] ORDER BY id" 
                 ;

            var Adapter = new SqlDataAdapter(dispositionSQL, conn);
            Adapter.TableMappings.Add("Table", "SteelList");
            Adapter.TableMappings.Add("Table1", "StandardEGPList");
            Adapter.TableMappings.Add("Table2", "StandardGPList");
            Adapter.TableMappings.Add("Table3", "StandardRPList");
            Adapter.TableMappings.Add("Table4", "StandardSPList");
            Adapter.TableMappings.Add("Table5", "StandardScrewList");
            Adapter.TableMappings.Add("Table6", "FancyPlateList");
            Adapter.TableMappings.Add("Table7", "MoldTypeList");
            Adapter.TableMappings.Add("Table8", "MoldHoleList");
            Adapter.TableMappings.Add("Table9", "CustomerList");
            Adapter.TableMappings.Add("Table10", "SeriesSizeItemList");
            Adapter.TableMappings.Add("Table11", "QuoUserList");
            Adapter.TableMappings.Add("Table12", "StandardBoardThickList");
            Adapter.TableMappings.Add("Table13", "StandardBoardWidthList");
            Adapter.TableMappings.Add("Table14", "StandardSPScrewMesonList");
            Adapter.TableMappings.Add("Table15", "NormBoardItemSub");
            Adapter.TableMappings.Add("Table16", "PullingSizeList");

            DataSet DispostionData = new DataSet();
            Adapter.Fill(DispostionData);

            InitSteelDisposition(DispostionData);
            InitEGPDisposition(DispostionData);
            InitGPDisposition(DispostionData);
            InitRPDisposition(DispostionData);
            InitSPDisposition(DispostionData);
            InitScrewDisposition(DispostionData);
            InitCBDisposition(DispostionData);
            InitMoldDisposition(DispostionData);
            InitMoldHoleDisposition(DispostionData);
            InitPullingSizeDisposition(DispostionData);
            InitCustomerDisposition(DispostionData);
            InitBSIDisposition(DispostionData);
            InitQuoUserDisposition(DispostionData);
            InitBTDisposition(DispostionData);
            InitBWDisposition(DispostionData);
            InitNormDisposition(DispostionData);
            InitSPScrewMeson(DispostionData);
            conn.Close();

        }

        public void InitSPScrewMeson(DataSet data)
        {
            ParamsConfigData.StandardSPScrewMesonList = new List<StandardSPScrewMeson>();
            DataTable temp = data.Tables["StandardSPScrewMesonList"];
            if (temp.Rows.Count > 0)
            {
                for (int i = 0; i < temp.Rows.Count; i++)
                {
                    StandardSPScrewMeson item = new StandardSPScrewMeson();
                    item.spDim = Convert.ToInt32(temp.Rows[i]["spDim"]);
                    item.spTD = Convert.ToInt32(temp.Rows[i]["spTD"]);
                    item.spTH = Convert.ToInt32(temp.Rows[i]["spTH"]);
                    item.MesonScrewDim = Convert.ToInt32(temp.Rows[i]["MesonScrewDim"]);
                    item.MesonScrewL = Convert.ToInt32(temp.Rows[i]["MesonScrewL"]);
                    item.spMesonDim = Convert.ToDouble(temp.Rows[i]["spMesonDim"]);
                    item.spMesonTD = Convert.ToInt32(temp.Rows[i]["spMesonTD"]);
                    item.spMesonTH = Convert.ToInt32(temp.Rows[i]["spMesonTH"]);
                    ParamsConfigData.StandardSPScrewMesonList.Add(item);
                }
            }
        }

        public void InitBSIDisposition(DataSet data)
        {
            ParamsConfigData.StandardBoardRelItemList = new List<StandardSeriesRelItem>();
            DataTable temp = data.Tables["SeriesSizeItemList"];
            if (temp.Rows.Count > 0)
            {
                for (int i = 0; i < temp.Rows.Count; i++)
                {
                    StandardSeriesRelItem item = new StandardSeriesRelItem();
                    item.MouldSeries = Convert.ToString(temp.Rows[i]["MouldSeries"]);
                    item.ItemCode = Convert.ToString(temp.Rows[i]["ItemCode"]);
                    item.ItemName = Convert.ToString(temp.Rows[i]["ItemName"]);
                    item.ItemRemark = Convert.ToString(temp.Rows[i]["ItemRemark"]);

                    string ItemNumStr = Convert.ToString(temp.Rows[i]["ItemNum"]);
                    if(ItemNumStr != null && ItemNumStr != "")
                        item.ItemNum = Convert.ToInt32(ItemNumStr);

                    ParamsConfigData.StandardBoardRelItemList.Add(item);
                }
            }
        }

        //客户
        public void InitCustomerDisposition(DataSet data)
        {
          ParamsConfigData.CustomerList = new List<VCustomer>();
          DataTable temp = data.Tables["CustomerList"];
            if (temp.Rows.Count > 0)
            {
                for (int i = 0; i < temp.Rows.Count; i++)
                {
                    VCustomer item = new VCustomer();
                    item.customerNumber = Convert.ToString(temp.Rows[i]["customer_number"]);
                    item.customerAliasName = Convert.ToString(temp.Rows[i]["customer_alias_name"]);
                    item.salesPerson = Convert.ToString(temp.Rows[i]["sales_person"]);
                    item.showContent = item.customerNumber + " - " + item.customerAliasName + " - " + item.salesPerson;
                    item.OrgId = Convert.ToInt32(temp.Rows[i]["Org_Id"]);
                    item.local = Convert.ToString(temp.Rows[i]["local"]);
                    ParamsConfigData.CustomerList.Add(item);
                }
                if(RecognizeUtils.dataForm.CustomerSelect.Items.Count > 0)
                    RecognizeUtils.dataForm.CustomerSelect.Items.Clear();
                RecognizeUtils.dataForm.CustomerSelect.Items.AddRange(ParamsConfigData.CustomerList.ToArray());
                RecognizeUtils.dataForm.CustomerSelect.DisplayMember = "showContent";
                RecognizeUtils.dataForm.CustomerSelect.ValueMember = "customerNumber";
            }
        }

        //接单人员信息
        public void InitQuoUserDisposition(DataSet data)
        {
            ParamsConfigData.QuoUserList = new List<QuoUser>();
            DataTable temp = data.Tables["QuoUserList"];
            if(temp.Rows.Count > 0)
            {
                for(int i = 0; i < temp.Rows.Count; i++)
                {
                    QuoUser item = new QuoUser();
                    item.name = Convert.ToString(temp.Rows[i]["name"]);
                    item.code = Convert.ToString(temp.Rows[i]["code"]);
                    ParamsConfigData.QuoUserList.Add(item);
                }
            }
        }
        
        //手工模式 标准板厚信息
        public void InitBTDisposition(DataSet data)
        {
            ParamsConfigData.StandardBoardThickList = new List<StandardBoardThick>();
            DataTable temp = data.Tables["StandardBoardThickList"];
            if (temp.Rows.Count > 0)
            {
                for (int i = 0; i < temp.Rows.Count; i++)
                {
                    StandardBoardThick item = new StandardBoardThick();
                    item.boardCode = Convert.ToString(temp.Rows[i]["board_code"]);
                    item.boardName = Convert.ToString(temp.Rows[i]["board_name"]);
                    item.moldSize = Convert.ToInt32(temp.Rows[i]["mold_size"]);
                    item.sysShortName = Convert.ToString(temp.Rows[i]["sys_short_name"]);
                    item.boardThick = Convert.ToString(temp.Rows[i]["board_thick"]);
                    ParamsConfigData.StandardBoardThickList.Add(item);
                }
            }
        }

        //NormBoardItemSub
        public void InitNormDisposition(DataSet data)
        {
            ParamsConfigData.StandardBoardItemNormSubList = new List<StandardBoardItemNormSub>();
            DataTable temp = data.Tables["NormBoardItemSub"];
            if (temp.Rows.Count > 0)
            {
                for (int i = 0; i < temp.Rows.Count; i++)
                {
                    StandardBoardItemNormSub item = new StandardBoardItemNormSub();
                    item.category = Convert.ToString(temp.Rows[i]["category"]).Trim();
                    item.partCode = Convert.ToString(temp.Rows[i]["part_code"]).Trim();
                    item.partName = Convert.ToString(temp.Rows[i]["part_name"]).Trim();
                    item.aboutBoard = Convert.ToString(temp.Rows[i]["cb_id"]).Trim();
                    ParamsConfigData.StandardBoardItemNormSubList.Add(item);
                }
            }
        }

        //手动模式 标准板宽信息
        public void InitBWDisposition(DataSet data)
        {
            ParamsConfigData.StandardBoardWidthList = new List<StandBoardWidth>();
            DataTable temp = data.Tables["StandardBoardWidthList"];
            if (temp.Rows.Count > 0)
            {
                for (int i = 0; i < temp.Rows.Count; i++)
                {
                    StandBoardWidth item = new StandBoardWidth();
                    item.name = Convert.ToString(temp.Rows[i]["name"]).Trim();
                    item.series = Convert.ToString(temp.Rows[i]["series"]).Trim();
                    item.W = Convert.ToInt32(temp.Rows[i]["W"]);
                    item.xinhao = Convert.ToInt32(temp.Rows[i]["xinhao"]);
                    ParamsConfigData.StandardBoardWidthList.Add(item);
                }
            }
        }

        private void InitMoldHoleDisposition(DataSet data)
        {
            ParamsConfigData.MoldHoleList = new List<StandardHoleData>();
            DataTable temp = data.Tables["MoldHoleList"];
            if (temp.Rows.Count > 0)
            {
                for (int i = 0; i < temp.Rows.Count; i++)
                {
                    StandardHoleData item = new StandardHoleData();
                    item.MouldSize = Convert.ToInt32(temp.Rows[i]["MouldSize"]);
                    item.MouldSeries = Convert.ToString(temp.Rows[i]["MouldSeries"]);
                    item.Item = Convert.ToString(temp.Rows[i]["Item"]);
                    item.ItemDim = Convert.ToInt32(temp.Rows[i]["ItemDim"]);
                    item.ItemNum = Convert.ToInt32(temp.Rows[i]["ItemNum"]);
                    item.ItemW = Convert.ToInt32(temp.Rows[i]["ItemW"]);
                    item.ItemX = Convert.ToDouble(temp.Rows[i]["ItemX"]);
                    item.ItemY = Convert.ToDouble(temp.Rows[i]["ItemY"]);
                    ParamsConfigData.MoldHoleList.Add(item);
                }
            }
            ParamsConfigData.MoldHoleList = ParamsConfigData.MoldHoleList.OrderBy(item => item.ItemDim).ToList();
        }

        private void InitMoldDisposition(DataSet data)
        {
            ParamsConfigData.MoldTypeList = new List<StandardMoldType>();
            DataTable temp = data.Tables["MoldTypeList"];
            if (temp.Rows.Count > 0)
            {
                for (int i = 0; i < temp.Rows.Count; i++)
                {
                    StandardMoldType item = new StandardMoldType();
                    string shortName = Convert.ToString(temp.Rows[i]["short_name"]);
                    string category = Convert.ToString(temp.Rows[i]["category"]);
                    item.shortName = shortName;
                    item.category = category;
                    ParamsConfigData.MoldTypeList.Add(item);
                }
            }
            if (ParamsConfigData.MoldTypeList.Count > 0)
            {
                var target = RecognizeUtils.dataForm.FancySelectBox;
                target.Items.Clear();
                List<string> categoryList = ParamsConfigData.MoldTypeList.Select(item => item.category).ToList();
                for (int i = 0; i < categoryList.Count; i++)
                    target.Items.Add(categoryList[i]);
            }
        }

        //初始化钢种名称
        private void InitSteelDisposition(DataSet data)
        {
            ParamsConfigData.StandardSteelList = new List<StandardSteel>();
            DataTable temp = data.Tables["SteelList"];
            if (temp.Rows.Count > 0)
            {
                for (int i = 0; i < temp.Rows.Count; i++)
                {
                    StandardSteel tempItem = new StandardSteel();
                    string ItemNumber = Convert.ToString(temp.Rows[i]["Item_Number"]);
                    string ItemDesc = Convert.ToString(temp.Rows[i]["Item_Desc"]);
                    tempItem.ItemNumber = ItemNumber;
                    tempItem.ItemDesc = ItemDesc;
                    ParamsConfigData.StandardSteelList.Add(tempItem);
                }
            }
            if (RecognizeUtils.dataForm.steelWindow.SteelBox.Items.Count > 0)
                RecognizeUtils.dataForm.steelWindow.SteelBox.Items.Clear();
            RecognizeUtils.dataForm.steelWindow.SteelBox.Items.AddRange(ParamsConfigData.StandardSteelList.ToArray());
            RecognizeUtils.dataForm.steelWindow.SteelBox.DisplayMember = "ItemDesc";
            RecognizeUtils.dataForm.steelWindow.SteelBox.ValueMember = "ItemNumber";
        }

        private void InitEGPDisposition(DataSet data)
        {
            ParamsConfigData.StandardEGPList = new List<StandardEGP>();
            DataTable temp = data.Tables["StandardEGPList"];
            if (temp.Rows.Count > 0)
            {
                for (int i = 0; i < temp.Rows.Count; i++)
                {
                    StandardEGP item = new StandardEGP();
                    int Dimension = Convert.ToInt32(temp.Rows[i]["Dimension"]);
                    int TH = Convert.ToInt32(temp.Rows[i]["TH"]);
                    int TD = Convert.ToInt32(temp.Rows[i]["TD"]);
                    int BushSize = Convert.ToInt32(temp.Rows[i]["BushSize"]);
                    int BushTH = Convert.ToInt32(temp.Rows[i]["BushTH"]);
                    int BushTD = Convert.ToInt32(temp.Rows[i]["BushTD"]);
                    item.Dimension = Dimension;
                    item.TH = TH;
                    item.TD = TD;
                    item.BushSize = BushSize;
                    item.BushTH = BushTH;
                    item.BushTD = BushTD;
                    ParamsConfigData.StandardEGPList.Add(item);
                }
            }
        }
      
        //导柱
       private void InitGPDisposition(DataSet data)
        {
            ParamsConfigData.StandardGPList = new List<StandardGPSP>();
            DataTable temp = data.Tables["StandardGPList"];
            if (temp.Rows.Count > 0)
            {
                for (int i = 0; i < temp.Rows.Count; i++)
                {
                    StandardGPSP item = new StandardGPSP();
                    int Dimension = Convert.ToInt32(temp.Rows[i]["Dimension"]);
                    int TH = Convert.ToInt32(temp.Rows[i]["TH"]);
                    int TD = Convert.ToInt32(temp.Rows[i]["TD"]);
                    int BushSize = Convert.ToInt32(temp.Rows[i]["BushSize"]);
                    int BushTH = Convert.ToInt32(temp.Rows[i]["BushTH"]);
                    int BushTD = Convert.ToInt32(temp.Rows[i]["BushTD"]);
                    int BK_1 = Convert.ToInt32(temp.Rows[i]["BK_1"]);
                    int BK_2 = Convert.ToInt32(temp.Rows[i]["BK_2"]);
                    item.Dimension = Dimension;
                    item.TH = TH;
                    item.TD = TD;
                    item.BushSize = BushSize;
                    item.BushTH = BushTH;
                    item.BushTD = BushTD;
                    item.BK_1 = BK_1;
                    item.BK_2 = BK_2;
                    ParamsConfigData.StandardGPList.Add(item);
                }
            }
        }

        private void InitRPDisposition(DataSet data)
        {
            ParamsConfigData.StandardRPList = new List<StandardRP>();
            DataTable temp = data.Tables["StandardRPList"];
            if(temp.Rows.Count > 0)
            {
                for (int i = 0; i < temp.Rows.Count; i++)
                {
                    StandardRP item = new StandardRP();
                    int Dimension = Convert.ToInt32(temp.Rows[i]["Dimension"]);
                    int TH = Convert.ToInt32(temp.Rows[i]["TH"]);
                    int TD = Convert.ToInt32(temp.Rows[i]["TD"]);
                    item.Dimension = Dimension;
                    item.TH = TH;
                    item.TD = TD;
                    ParamsConfigData.StandardRPList.Add(item);
                }
            }
            ParamsConfigData.StandardRPList = ParamsConfigData.StandardRPList.OrderBy(item => item.Dimension).ToList();
        }

        //拉杆表
        private void InitSPDisposition(DataSet data)
        {
            ParamsConfigData.StandardSPList = new List<StandardGPSP>();
            DataTable temp = data.Tables["StandardSPList"];
            if (temp.Rows.Count > 0)
            {
                for (int i = 0; i < temp.Rows.Count; i++)
                {
                    StandardGPSP item = new StandardGPSP();
                    int Dimension = Convert.ToInt32(temp.Rows[i]["Dimension"]);
                    int TH = Convert.ToInt32(temp.Rows[i]["TH"]);
                    int TD = Convert.ToInt32(temp.Rows[i]["TD"]);
                    int BushSize = Convert.ToInt32(temp.Rows[i]["BushSize"]);
                    int BushTH = Convert.ToInt32(temp.Rows[i]["BushTH"]);
                    int BushTD = Convert.ToInt32(temp.Rows[i]["BushTD"]);
                    int BK_1 = Convert.ToInt32(temp.Rows[i]["BK_1"]);
                    int BK_2 = Convert.ToInt32(temp.Rows[i]["BK_2"]);
                    item.Dimension = Dimension;
                    item.TH = TH;
                    item.TD = TD;
                    item.BushSize = BushSize;
                    item.BushTH = BushTH;
                    item.BushTD = BushTD;
                    item.BK_1 = BK_1;
                    item.BK_2 = BK_2;
                    ParamsConfigData.StandardSPList.Add(item);
                }
            }
        }

        private void InitScrewDisposition(DataSet data)
        {
            ParamsConfigData.StandardScrewList = new List<StandardScrew>();
            DataTable temp = data.Tables["StandardScrewList"];
            for (int i = 0; i < temp.Rows.Count; i++)
            {
                StandardScrew item = new StandardScrew();
                int Dimension = Convert.ToInt32(temp.Rows[i]["Dimension"]);
                decimal BaseDimension = Convert.ToDecimal(temp.Rows[i]["BaseDimension"]);
                decimal ThroughDimension = Convert.ToDecimal(temp.Rows[i]["ThroughDimension"]);
                decimal TH = Convert.ToDecimal(temp.Rows[i]["TH"]);
                decimal TD = Convert.ToDecimal(temp.Rows[i]["TD"]);
                decimal BlindDepth = Convert.ToDecimal(temp.Rows[i]["BlindDepth"]);
                decimal ScrewDepth = Convert.ToDecimal(temp.Rows[i]["ScrewDepth"]);
                item.Dimension = Dimension;
                item.BaseDimension = BaseDimension;
                item.ThroughDimension = ThroughDimension;
                item.TH = TH;
                item.TD = TD;
                item.BlindDepth = BlindDepth;
                item.ScrewDepth = ScrewDepth;
                ParamsConfigData.StandardScrewList.Add(item);
            }
        }

        //花式和板的对应关系
        private void InitCBDisposition(DataSet data)
        {
            ParamsConfigData.FancyPlateList = new List<StandardCategoryBoard>();
            DataTable temp = data.Tables["FancyPlateList"];
            for (int i = 0; i < temp.Rows.Count; i++)
            {
                StandardCategoryBoard item = new StandardCategoryBoard();
                string category = Convert.ToString(temp.Rows[i]["category"]);
                string board_name = Convert.ToString(temp.Rows[i]["board_name"]);
                int sortNum = Convert.ToInt32(temp.Rows[i]["sort_num"]);
                string shortName = Convert.ToString(temp.Rows[i]["short_name"]);
                string board_code = Convert.ToString(temp.Rows[i]["board_code"]);
                item.category = category;
                item.boardName = board_name;
                item.sortNum = sortNum;
                item.shortName = shortName;
                item.boardCode = board_code;
                ParamsConfigData.FancyPlateList.Add(item);
            }   
        }

        //初始化拉令标准参数数据
        private void InitPullingSizeDisposition(DataSet data)
        {
            ParamsConfigData.StandardPullingList = new List<StandardPulling>();
            DataTable temp = data.Tables["PullingSizeList"];
            for (int i = 0; i < temp.Rows.Count; i++)
            {
                StandardPulling item = new StandardPulling();
                item.sortNum = i;
                item.minW = Convert.ToInt32(temp.Rows[i]["minW"]);
                item.maxW = Convert.ToInt32(temp.Rows[i]["maxW"]);
                item.minL = Convert.ToInt32(temp.Rows[i]["minL"]);
                item.maxL = Convert.ToInt32(temp.Rows[i]["maxL"]);
                item.AB = Convert.ToInt32(temp.Rows[i]["AB"]);
                item.skmb = Convert.ToInt32(temp.Rows[i]["skmb"]);
                item.tuoban = Convert.ToInt32(temp.Rows[i]["tuoban"]);
                item.dbmb = Convert.ToInt32(temp.Rows[i]["dbmb"]);
                item.tuiban = Convert.ToInt32(temp.Rows[i]["tuiban"]);
                item.fangtie = Convert.ToInt32(temp.Rows[i]["fangtie"]);
                item.zhenban = Convert.ToInt32(temp.Rows[i]["zhenban"]);
                ParamsConfigData.StandardPullingList.Add(item);
            }
        }

        public static List<AMTypeUPloadRecordInfo> InitRecordDisposition(DataSet data,string TageType)
        {
            List<AMTypeUPloadRecordInfo> resList = new List<AMTypeUPloadRecordInfo>();
            DataTable temp = data.Tables[TageType];
            if(temp != null)
            {
                for (int i = 0; i < temp.Rows.Count; i++)
                {
                    AMTypeUPloadRecordInfo item = new AMTypeUPloadRecordInfo();
                    item.uploadTime = Convert.ToDateTime(temp.Rows[i]["uploadTime"]);
                    item.customer = Convert.ToString(temp.Rows[i]["customer"]);
                    item.batchNum = Convert.ToString(temp.Rows[i]["batchNum"]);
                    var MoldTypeValue = temp.Rows[i]["MoldType"];
                    if(MoldTypeValue != null)
                        item.moldType = Convert.ToString(temp.Rows[i]["MoldType"]);
                    item.fancy = Convert.ToString(temp.Rows[i]["fancy"]);
                    item.modeNum = Convert.ToString(temp.Rows[i]["modeNum"]);
                    item.modeSize = Convert.ToString(temp.Rows[i]["modeSize"]);
                    item.jobNumberName = Convert.ToString(temp.Rows[i]["jobNumberName"]);
                    item.UID = Convert.ToString(temp.Rows[i]["UID"]);
                    item.quoInfo = Convert.ToString(temp.Rows[i]["quoInfo"]);
                    item.processInfo = Convert.ToString(temp.Rows[i]["processInfo"]);
                    item.dwgfilePath = Convert.ToString(temp.Rows[i]["dwgFilePath"]);
                    item.dwgfileName = Convert.ToString(temp.Rows[i]["dwgFileName"]);
                    item.selectAreaCondiInfo = Convert.ToString(temp.Rows[i]["selectAreaCondiction"]);
                    string uType = temp.Rows[i]["uploadType"].ToString();
                    if(!uType.Equals(""))
                        item.uploadType = Convert.ToInt32(temp.Rows[i]["uploadType"]);
                    resList.Add(item);
                }
            }
            return resList;
        }

        //保存上传记录数据到数据库
        public static void SaveUploadRecordToDB(AMTypeUPloadRecordInfo info,string JobNumberName)
        {
            string VNum = DataForm.VersionNum;
            string moldType = CADCommonForm.MoldTypeStr;
            string fancy = (string)RecognizeUtils.dataForm.FancySelectBox.SelectedItem;
            fancy = fancy.Trim();
            string SQLServerAddr = "139.159.178.26";
            string UID = "CAM";
            string PWD = "CAM";
            string SQLConnectionString = $"Server={SQLServerAddr};Database=DXMG;UID={UID};PWD={PWD}";
            using (SqlConnection conn = new SqlConnection(SQLConnectionString))
            {
                conn.Open();
                //创建时间
                var nowTime = DateTime.Now;
                string strpro = $"insert into [R2D_UploadRecord] (UID,customer,batchNum," +
                    $"MoldType,fancy,modeNum,modeSize,jobNumber,jobNumberName," +
                    $"dwgFilePath,dwgFileName,selectAreaCondiction,quoInfo,processInfo,uploadType,uploadTime,VerNum) " +
                    $"values ('{info.UID}','{info.customer}','{info.batchNum}'," +
                    $" '{moldType}', '{fancy}','{info.modeNum}','{info.modeSize}','{info.jobNumber}','{JobNumberName}'," +
                    $"'{info.dwgfilePath}','{info.dwgfileName}','{info.selectAreaCondiInfo}','{info.quoInfo}','{info.processInfo}','{info.uploadType}', '{info.uploadTime}','{VNum}') ";
                var value = new SqlCommand(strpro, conn).ExecuteNonQuery();
                if (value != 1)
                    MessageBox.Show(UserPromptErrorType.SaveUploadRecordError);
                conn.Close();
            }
        }

        //动态查询上传记录
        public static void SearchRecordByCondi(AMTypeUPloadRecordInfo info)
        {
            string tagType = "SearchUploadRecordList";
            DateTime SearchTime = info.uploadTime;
            string customer = info.customer;
            string fancy = info.fancy;
            string modeNum = info.modeNum;
            string batchNum = info.batchNum;
            string jobNumber = info.jobNumber;
            ParamsConfigData.userAMUploadRIList = new List<AMTypeUPloadRecordInfo>();
            string SQLServerAddr = "139.159.178.26";
            string UID = "CAM";
            string PWD = "CAM";
            string SQLConnectionString = $"Server={SQLServerAddr};Database=DXMG;UID={UID};PWD={PWD}";
            SqlConnection sqlConnection = new SqlConnection(SQLConnectionString);
            var conn = sqlConnection;
            conn.Open();

            string strpro = $"SELECT top(100) * FROM [R2D_UploadRecord] WHERE 1 = 1";
            if (customer != null)
                strpro += " AND customer = '" + customer + "'";
            if (fancy != null)
                strpro += " AND fancy = '" + fancy + "'";
            if (modeNum != null)
                strpro += " AND modeNum like '%" + modeNum + "%'";
            if (batchNum != null)
                strpro += " AND batchNum like '%" + batchNum + "%'";
            if (jobNumber != null)
                strpro += " AND jobNumber = '" + jobNumber + "'";

            strpro += "ORDER BY uploadTime DESC";
            var Adapter = new SqlDataAdapter(strpro, conn);
            Adapter.TableMappings.Add("Table", tagType);
            DataSet DispostionData = new DataSet();
            Adapter.Fill(DispostionData);
            conn.Close();
            ParamsConfigData.userAMUploadRIList = InitRecordDisposition(DispostionData,tagType);
        }

    }
}
